import pymysql #PyMySQL 1.1.1


class Longguo():
    def connect_database(self):
        # 连接数据库
        self.db = pymysql.connect(
            host='10.59.9.24',
            user='wms',
            password='Wms123456!',
            database='wms',
            cursorclass=pymysql.cursors.DictCursor  # 使用DictCursor
        )
        return self.db

    # 将数据以字典的形式打印出来
    def list_of_dicts(self, sql):
        # 创建游标
        cur = self.connect_database().cursor()
        # 输入sql语句
        cur.execute(sql)
        self.data = cur.fetchall()  # 直接获取字典格式的数据
        return self.data

if __name__ == '__main__':

    lg = Longguo()
    platform_name = lg.list_of_dicts("SELECT platform_name FROM ba_platform ORDER BY create_date DESC LIMIT 1;")
    print(platform_name[0]["platform_name"])